// AUTO GENERATED CODE!
// CODE GENERATOR WILL NOT PRESERVE MANUAL CHANGES TO THIS CODE!
// 

// MIT License (MIT)
// 
// Copyright (c) 2014 K Ercan Turkarslan
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// 


using System;

namespace Mios.Generated.ServiceFiles
{
    // Generated from S_SerialPort1.xml
    
    public class SerialPort1Service : MiosService
    {
        #region path : String;
        private String _mpath;
        
        public String path
        {
            get
            {
                return _mpath ?? Getpath();
            }
        }
        
        // WARNING: Service Description File does not contain any Get Action with a
        // argument related to this State Variable.
        // 
        // This may be due to a typo while defining the Get Action or state variable.
        // This may also be intentional. Code generator assumes this was a mistake and
        // generates this Get Action.
        
        #region Action Getpath() : String;
        public String Getpath()
        {
            _mpath = FromLuupString(Engine.Luup_VariableGet(base.DeviceId, base.ServiceId, "path"));
            
            return _mpath;
        }
        #endregion Action Getpath
        
        #endregion
        
        #region baud : UInt32;
        private UInt32? _mbaud;
        
        public UInt32 baud
        {
            get
            {
                return _mbaud ?? Getbaud();
            }
        }
        
        #region Action Setbaud(UInt32 newbaud) : String;
        public String Setbaud(UInt32 newbaud)
        {
            switch(newbaud.ToString())
            {
                case "300":
                case "1200":
                case "2400":
                case "4800":
                case "9600":
                case "19200":
                case "38400":
                case "57600":
                case "115200":
                case "230400":
                    break;
                
                default:
                    throw new ArgumentOutOfRangeException("newbaud");
            }
            
            return Engine.Luup_CallAction(base.DeviceId, base.ServiceId, "Setbaud",
                String.Format("newbaud={0}", ToLuup(_mbaud = newbaud)));
        }
        #endregion Action Setbaud
        
        // WARNING: Service Description File does not contain any Get Action with a
        // argument related to this State Variable.
        // 
        // This may be due to a typo while defining the Get Action or state variable.
        // This may also be intentional. Code generator assumes this was a mistake and
        // generates this Get Action.
        
        #region Action Getbaud() : UInt32;
        public UInt32 Getbaud()
        {
            _mbaud = FromLuupUInt32(Engine.Luup_VariableGet(base.DeviceId, base.ServiceId, "baud"));
            
            return _mbaud.Value;
        }
        #endregion Action Getbaud
        
        #endregion
        
        #region stopbits : Byte;
        private Byte? _mstopbits;
        
        public Byte stopbits
        {
            get
            {
                return _mstopbits ?? Getstopbits();
            }
        }
        
        #region Action Setstopbits(Byte newstopbits) : String;
        public String Setstopbits(Byte newstopbits)
        {
            switch(newstopbits.ToString())
            {
                case "0":
                case "1":
                case "2":
                    break;
                
                default:
                    throw new ArgumentOutOfRangeException("newstopbits");
            }
            
            return Engine.Luup_CallAction(base.DeviceId, base.ServiceId, "Setstopbits",
                String.Format("newstopbits={0}", ToLuup(_mstopbits = newstopbits)));
        }
        #endregion Action Setstopbits
        
        // WARNING: Service Description File does not contain any Get Action with a
        // argument related to this State Variable.
        // 
        // This may be due to a typo while defining the Get Action or state variable.
        // This may also be intentional. Code generator assumes this was a mistake and
        // generates this Get Action.
        
        #region Action Getstopbits() : Byte;
        public Byte Getstopbits()
        {
            _mstopbits = FromLuupByte(Engine.Luup_VariableGet(base.DeviceId, base.ServiceId, "stopbits"));
            
            return _mstopbits.Value;
        }
        #endregion Action Getstopbits
        
        #endregion
        
        #region databits : Byte;
        private Byte? _mdatabits;
        
        public Byte databits
        {
            get
            {
                return _mdatabits ?? Getdatabits();
            }
        }
        
        #region Action Setdatabits(Byte newdatabits) : String;
        public String Setdatabits(Byte newdatabits)
        {
            switch(newdatabits.ToString())
            {
                case "7":
                case "8":
                    break;
                
                default:
                    throw new ArgumentOutOfRangeException("newdatabits");
            }
            
            return Engine.Luup_CallAction(base.DeviceId, base.ServiceId, "Setdatabits",
                String.Format("newdatabits={0}", ToLuup(_mdatabits = newdatabits)));
        }
        #endregion Action Setdatabits
        
        // WARNING: Service Description File does not contain any Get Action with a
        // argument related to this State Variable.
        // 
        // This may be due to a typo while defining the Get Action or state variable.
        // This may also be intentional. Code generator assumes this was a mistake and
        // generates this Get Action.
        
        #region Action Getdatabits() : Byte;
        public Byte Getdatabits()
        {
            _mdatabits = FromLuupByte(Engine.Luup_VariableGet(base.DeviceId, base.ServiceId, "databits"));
            
            return _mdatabits.Value;
        }
        #endregion Action Getdatabits
        
        #endregion
        
        #region parity : String;
        private String _mparity;
        
        public String parity
        {
            get
            {
                return _mparity ?? Getparity();
            }
        }
        
        #region Action Setparity(String newparity) : String;
        public String Setparity(String newparity)
        {
            if (String.IsNullOrEmpty(newparity))
                throw new ArgumentNullException("newparity");
            
            switch(newparity)
            {
                case "none":
                case "even":
                case "odd":
                    break;
                
                default:
                    throw new ArgumentOutOfRangeException("newparity");
            }
            
            return Engine.Luup_CallAction(base.DeviceId, base.ServiceId, "Setparity",
                String.Format("newparity={0}", ToLuup(_mparity = newparity)));
        }
        #endregion Action Setparity
        
        // WARNING: Service Description File does not contain any Get Action with a
        // argument related to this State Variable.
        // 
        // This may be due to a typo while defining the Get Action or state variable.
        // This may also be intentional. Code generator assumes this was a mistake and
        // generates this Get Action.
        
        #region Action Getparity() : String;
        public String Getparity()
        {
            _mparity = FromLuupString(Engine.Luup_VariableGet(base.DeviceId, base.ServiceId, "parity"));
            
            return _mparity;
        }
        #endregion Action Getparity
        
        #endregion
        
        #region vendor : String;
        // WARNING: This state variable was not defined in the Service Description file.
        // However it was referenced by one or more Actions as their related state variable.
        // Or it was returned by Vera in USER_DATA xml.
        // This may be due to a typo in RelatedStateVariable definition or missing State Variable.
        
        private String _mvendor;
        
        public String vendor
        {
            get
            {
                return _mvendor ?? Getvendor();
            }
        }
        
        // WARNING: Service Description File does not contain any Get Action with a
        // argument related to this State Variable.
        // 
        // This may be due to a typo while defining the Get Action or state variable.
        // This may also be intentional. Code generator assumes this was a mistake and
        // generates this Get Action.
        
        #region Action Getvendor() : String;
        public String Getvendor()
        {
            _mvendor = FromLuupString(Engine.Luup_VariableGet(base.DeviceId, base.ServiceId, "vendor"));
            
            return _mvendor;
        }
        #endregion Action Getvendor
        
        #endregion
        
        #region product : String;
        // WARNING: This state variable was not defined in the Service Description file.
        // However it was referenced by one or more Actions as their related state variable.
        // Or it was returned by Vera in USER_DATA xml.
        // This may be due to a typo in RelatedStateVariable definition or missing State Variable.
        
        private String _mproduct;
        
        public String product
        {
            get
            {
                return _mproduct ?? Getproduct();
            }
        }
        
        // WARNING: Service Description File does not contain any Get Action with a
        // argument related to this State Variable.
        // 
        // This may be due to a typo while defining the Get Action or state variable.
        // This may also be intentional. Code generator assumes this was a mistake and
        // generates this Get Action.
        
        #region Action Getproduct() : String;
        public String Getproduct()
        {
            _mproduct = FromLuupString(Engine.Luup_VariableGet(base.DeviceId, base.ServiceId, "product"));
            
            return _mproduct;
        }
        #endregion Action Getproduct
        
        #endregion
        
        
        #region Method SetVariable(String name, String value) : Boolean;
        internal override Boolean SetVariable(String name, String value)
        {
            switch(name)
            {
                case "baud":
                    _mbaud = FromLuupUInt32(value); return true;
                case "databits":
                    _mdatabits = FromLuupByte(value); return true;
                case "parity":
                    _mparity = FromLuupString(value); return true;
                case "path":
                    _mpath = FromLuupString(value); return true;
                case "product":
                    _mproduct = FromLuupString(value); return true;
                case "stopbits":
                    _mstopbits = FromLuupByte(value); return true;
                case "vendor":
                    _mvendor = FromLuupString(value); return true;
                default:
                    return false;
            }
        }
        #endregion Method SetVariable
        
        public SerialPort1Service(MiosEngine engine, UInt32 deviceId, String serviceId)
            : base(engine, deviceId, serviceId)
        {
            
        } //End Constructor
    } //End of class
} //End of Namespace

